#pragma once
#include<iostream>
#include<stdio.h>
#include<string>
#include<functional>

using  func_t = std::function<int(int,int,char)>;

class Task
{
public:
    Task()
    {}
    Task(int x,int y,char op,func_t func)
    :_x(x),_y(y),_op(op),_callblack(func)
    {}
    std::string operator()()
    {
        int result = _callblack(_x,_y,_op);
        char buffer[1024];
        snprintf(buffer,sizeof(buffer),"%d %c %d = %d",_x,_op,_y,result);
        return buffer;
    }
    std::string toTaskString()
    {
        char buffer[1024];
        snprintf(buffer,sizeof(buffer),"%d %c %d = ?",_x,_op,_y);
        return buffer;
    }
    // std
    ~Task()
    {}
private:
    int _x;
    int _y;
    char _op;
    func_t _callblack;
};

int mymath(int x, int y, char op)
{
    switch (op)
    {
    case '+':
        return x + y;
        break;
    case '-':
        return x - y;
        break;
    case '*':
        return x * y;
        break;
    case '/':
        if (y == 0)
        {
            std::cout << "div zero error!" << std::endl;
            return -1;
        }
        else
            return x / y;
        break;
    case '%':
        if (y == 0)
        {
            std::cout << "mod zero error!" << std::endl;
            return -1;
        }
        else
            return x % y;
        break;
    default:
        std::cout << "输入非法" << std::endl;
        break;
    }
}